import modelExtend from '../../../utils/modelExtend';
import HttpModel from '../../../models/http';
import {
    queryPost
} from '@/services/common'

let electricFenceMng = {
    namespace: 'electricFenceMng',
    state: {
        vehicleData: {
            rows: [],
            pagination: {},
        },
        modalLoading: false
    },
    effects: {
        *getVehicleList({ payload, callback }, { put, call }) {
            yield put({
                type: "save",
                payload: { modalLoading: true },
            });
            const response = yield call(queryPost, payload);
            if (response.statusCode === '0') {
                yield put({
                    type: "save",
                    payload: { modalLoading: false, vehicleData: response.data },
                });
                if (callback) callback(response);
            }
            return response;
        },
        *initData({ payload, callback }, { call, put }) {
            yield put({
                type: 'req',
                payload: {
                    pageData: {
                        list: [],
                        rows: [],
                        pagination: {},
                    },
                    data: {},
                },
            });
        },
    },

    reducers: {
        save(state, action) {
            return {
                ...state,
                ...action.payload,
            };
        },
    },
};
electricFenceMng = modelExtend(HttpModel, electricFenceMng);
export default electricFenceMng;